package com.cat.greedyAlgorithm;

import java.io.*;
import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://pintia.cn/problem-sets/91827364500/exam/problems/91827367873
 * @create 2025/10/9 20:32
 * @since JDK17
 */

public class Solution69 {
    static int N = 251, n, m, t;
    static int[][] tree = new int[N][2];
    static int[][] dp = new int[N][N];
    static int compute() {
        Arrays.sort(tree, 1, n + 1, (a, b) -> a[1] - b[1]);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - 1] + tree[i][0] + tree[i][1] * (j - 1));
            }
        }

        return dp[n][m];
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        t = ((int) in.nval);
        for (int i = 0; i < t; i++) {
            in.nextToken();
            n = ((int) in.nval);
            in.nextToken();
            m = ((int) in.nval);
            for (int j = 1; j <= n; j++) {
                in.nextToken();
                tree[i][0] = ((int) in.nval);
            }
            for (int j = 1; j <= n; j++) {
                in.nextToken();
                tree[i][1] = ((int) in.nval);
            }
            out.println(compute());
        }

        br.close();
        out.flush();
        out.close();
    }
}
